/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmCadastraPlanoContas.java
 *
 * Created on 23/09/2009, 12:43:23
 */

package planocontas.telas;

import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import planocontas.bd.PlanoContasDAO;
import planocontas.classes.PlanoContas;

/**
 *
 * @author Wolverine
 */
public class FrmCadastraPlanoContas extends javax.swing.JFrame{

    /** Creates new form FrmCadastraPlanoContas */
    public FrmCadastraPlanoContas(PlanoContas planoContas){
        initComponents();
        this.setLocationRelativeTo(null);
        setVisible(true);
        try {
            planoContasDAO = new PlanoContasDAO();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
            ex.printStackTrace();
        }
        this.planoContas = planoContas;
        if (planoContas != null){
            populaTela();
        }
        }
    private void populaTela() {
        descricaojTextField.setText(planoContas.getDescricao());
    }
        /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cadastraPlanojPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        descricaojTextField = new javax.swing.JTextField();
        descricaojLabel = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        salvarTelajButton = new javax.swing.JButton();
        fecharTelajButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro de plano de Contas");
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        cadastraPlanojPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        cadastraPlanojPanel.setPreferredSize(new java.awt.Dimension(800, 600));
        URL url = this.getClass().getResource("/imagens/logo_mini.png");
        Image imagemTitulo = Toolkit.getDefaultToolkit().getImage(url);
        this.setIconImage(imagemTitulo);
        try{
            UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
        }catch (Exception e){
            e.printStackTrace();
        }
        cadastraPlanojPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        jPanel1.add(descricaojTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, 370, -1));

        descricaojLabel.setText("Descrição");
        jPanel1.add(descricaojLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, 20));

        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        salvarTelajButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/tick.png"))); // NOI18N
        salvarTelajButton.setText("Salvar");
        salvarTelajButton.setToolTipText("Salvar Lançamento");
        salvarTelajButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarTelajButtonActionPerformed(evt);
            }
        });
        jPanel3.add(salvarTelajButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 10, -1, -1));

        fecharTelajButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/cross.png"))); // NOI18N
        fecharTelajButton.setText("Fechar");
        fecharTelajButton.setToolTipText("Fechar");
        fecharTelajButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fecharTelajButtonActionPerformed(evt);
            }
        });
        jPanel3.add(fecharTelajButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 8, -1, -1));

        jPanel1.add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, 370, 40));

        cadastraPlanojPanel.add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 400, 120));

        getContentPane().add(cadastraPlanojPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 420, 140));

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void fecharTelajButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fecharTelajButtonActionPerformed
        this.dispose();
    }//GEN-LAST:event_fecharTelajButtonActionPerformed
    private void salvarTelajButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarTelajButtonActionPerformed
        this.planoContas.setDescricao(descricaojTextField.getText());
        try{
        planoContasDAO.salvar(planoContas);
        JOptionPane.showMessageDialog(this,"Dados salvos com sucesso");
        }catch (Exception ex){
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this,"Dados não foram salvos");
        }
    }//GEN-LAST:event_salvarTelajButtonActionPerformed
    /**
    * @param args the command line arguments
    */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel cadastraPlanojPanel;
    private javax.swing.JLabel descricaojLabel;
    private javax.swing.JTextField descricaojTextField;
    private javax.swing.JButton fecharTelajButton;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JButton salvarTelajButton;
    // End of variables declaration//GEN-END:variables
    private PlanoContas planoContas;
    private PlanoContasDAO planoContasDAO;
}
